package logic

import (
	"context"
	"week3/api/internal/svc"
	"week3/api/internal/types"
	"week3/rpc/goods"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListLogic) List(req *types.GoodsListRequest) (resp *types.GoodsListResponse, err error) {
	rpcResp, err := l.svcCtx.Rpc.GoodsList(l.ctx, &goods.Request{})
	if err != nil {
		return nil, err
	}

	return &types.GoodsListResponse{
		Data: rpcResp.String(),
	}, nil
}
